package com.cl.core.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cl.core.dto.PagingReqDTO;
import com.cl.core.pojo.PlatformMenus;
import com.cl.core.service.impl.MenuServiceImpl;
import com.cl.utility.constant.Constant;
import com.cl.utility.constant.Message;
import com.cl.utility.pojo.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liddhappy
 * @description menu 接口
 * @createTime 2022/12/3 21:23
 */
@RestController
@RequestMapping("/menu")
@Api(tags = "菜单接口")
public class MenusController {
    @Autowired
    MenuServiceImpl menuService;

    @PostMapping("/add")
    @ApiOperation(value = "添加菜单")
    public ResultCode<PlatformMenus> addMenu(@RequestBody PlatformMenus menus) {
        menuService.addMenu(menus);
        return new ResultCode<>(Message.Success(Constant.ADD_SUCCESS), menus);
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除菜单")
    public ResultCode<PlatformMenus> deleteMenu(String menuId) {
        PlatformMenus platformMenus = menuService.selectMenu(menuId);
        menuService.deleteMenu(menuId);
        return new ResultCode<>(Message.Success(Constant.DELETE_SUCCESS), platformMenus);
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新菜单")
    public ResultCode<PlatformMenus> updateMenu(@RequestBody PlatformMenus menus) {
        menuService.updateMenu(menus);
        return new ResultCode<>(Message.Success(Constant.UPDATE_SUCCESS), menus);
    }

    @GetMapping("/get")
    @ApiOperation(value = "获取菜单")
    public ResultCode<PlatformMenus> getMenu(String menuId) {
        PlatformMenus platformMenus = menuService.selectMenu(menuId);
        return new ResultCode<>(Message.Success(Constant.SELECT_SUCCESS), platformMenus);
    }

    @PostMapping(value = "/paging")
    @ApiOperation(value = "分页查找")
    public ResultCode<IPage<PlatformMenus>> paging(@RequestBody PagingReqDTO<PlatformMenus> reqDTO) {

        //分页查询并转换
        IPage<PlatformMenus> page = menuService.paging(reqDTO);

        return new ResultCode<>(Message.Success(Constant.SELECT_SUCCESS), page);
    }

}
